{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}

<div class="p-3">
		<form class="layui-form gg-form-bar border-t border-x">
		<div class="layui-input-inline">
			<select name="grade">
				
				<option value="3A">三年级上册</option>
				<option value="4A">四年级上册</option>
				<option value="5A">五年级上册</option>
				<option value="6A">六年级上册</option>
				<option value="7A">电脑编程上册</option>
				
			</select>
		</div>
		<div class="layui-input-inline" style="width:300px;">
			<input type="text" name="keywords" placeholder="请输入关键字" class="layui-input" autocomplete="off" />
		</div>
		<div class="layui-input-inline">
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="searchform">提交搜索</button>
		</div>
	</form>
<table class="layui-hide" id="treeTable" lay-filter="treeTable"></table>
	
</div>

<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<span class="layui-btn layui-btn-sm add-menu" lay-event="add" data-title="添加课程类别">+ 添加课程类别</span>
	</div>
</script>

<script type="text/html" id="barDemo">
<span class="layui-btn-group"><a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="read">查看</a><a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a><a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a></span>
</script>

{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool', 'treeGrid'];
	function gouguInit() {
		var  treeGrid = layui.treeGrid,table = layui.table,tool = layui.tool, form = layui.form;		
	
		layui.pageTable = treeGrid.render({
			id:'treeTable',
			elem: '#treeTable',//表格id
			title: '课程列表',
			idField: 'id',			
			url: '/admin/course_xinxikeji/index'
			//,treeSpid: '0' //最上级的父级id
			, treeId: 'id'  //树形id字段名称
			, treeUpId: 'pid'//树形父id字段名称
			, treeShowName: 'title'//以树形式显示的字段
			, height: 'full+60'//满屏-10,即预留底边10
			, isOpenDefault:false
			, toolbar: '#toolbarDemo'
			, page: false,
			limit: 120,

			cellMinWidth: 30,
			cols: [
				[
				{
					fixed: 'left',
					field: 'id',
					title: '编号',
					sort: true,
					align: 'center',
					width: 80
				},{
					field: 'grade',
					title: '年级A',
					sort: true,
					align: 'center',
					width: 100
				},{
					field: 'pid',
					title: '上一分级',
					align: 'center',
					width: 100
				},{

					field: 'title',
					sort: true,
					title: '课程标题',
				},{

					field: 'allow_ext',
					title: '上传扩展名',
					align: 'center',
					width: 100
				},{
					field: 'update_time',
					title: '更新时间',
					align: 'center',
					width: 100
				},{
					field: 'create_time',
					title: '创建时间',
					align: 'center',
					width: 100
				},{
					field: 'sort',
					title: '排序',
					align: 'center',
					width: 100
				},{
					field: 'uid',
					title: '用户id',
					align: 'center',
					width: 100
				},{
					field: 'status',
					title: '状态',
					align: 'center',
					width: 100
				},
				{
					fixed: 'right',					
					title: '操作',
					toolbar: '#barDemo',
					width: 136,
					align: 'center',

				}				
				]
			]
		});
		
		//监听表头工具栏事件
		treeGrid.on('toolbar(treeTable)', function(obj){
			if (obj.event === 'add') {
				tool.side("/admin/course_xinxikeji/add");
				return false;
			}
		});
	  $('body').on('click','.add-menu', function(){
			tool.side("/admin/course_xinxikeji/add");
			return;
		});

		//监听表格行工具事件
		treeGrid.on('tool(treeTable)', function(obj) {
			var data = obj.data;
			if (obj.event === 'read') {
				tool.side('/admin/course_xinxikeji/read?id='+obj.data.id);
			}
			else if (obj.event === 'edit') {
				tool.side('/admin/course_xinxikeji/edit?id='+obj.data.id);
			}
			else if (obj.event === 'del') {
				layer.confirm('确定要删除该记录吗?', {
					icon: 3,
					title: '提示'
				}, function(index) {
					let callback = function (e) {
						layer.msg(e.msg);
						if (e.code == 0) {
							obj.del();
						}
					}
					tool.delete("/admin/course_xinxikeji/del", { id: data.id }, callback);
					layer.close(index);
				});
			}
			return false;
		});

		//监听搜索提交
		form.on('submit(searchform)', function(data) {
			layui.pageTable.reload({
				where: {
					keywords: data.field.keywords,
					grade:data.field.grade,				
				},

			});
			return false;
		});
	}
</script>
{/block}
<!-- /脚本 -->